package com.ruitu.health_1.mvp.presenter;

import com.ruitu.arad.base.BasePresenter;
import com.ruitu.health_1.dao.bean.Category;
import com.ruitu.health_1.mvp.model.CategoryModel;
import com.ruitu.health_1.ui.fragment.Category2Fragment;
import com.ruitu.health_1.ui.fragment.CategoryFragment;
import com.ruitu.router_module.Logg;
import com.ruitu.router_module.bean.BaseResult2;
import com.ruitu.router_module.bean.product.ChildrenCategory;

import java.util.List;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

public class CategoryPresenter {

    public static class CategoryListP extends BasePresenter<CategoryFragment, CategoryModel.CategoryListM> {
        public Disposable getCategory() {
            return m.getCategory().subscribe(new Consumer<BaseResult2<List<Category>>>() {
                @Override
                public void accept(BaseResult2<List<Category>> listBaseResult) throws Exception {
                    v.hideProgress();
                    v.setData(listBaseResult.getData());
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    Logg.i("Error: " + throwable.getMessage());
                }
            });
        }
    }

    public static class Category2ListP extends BasePresenter<Category2Fragment, CategoryModel.Category2ListM> {
        public Disposable childrenCategory(String id) {
            return m.childrenCategory(id)
                    .subscribe(new Consumer<BaseResult2<List<ChildrenCategory>>>() {
                        @Override
                        public void accept(BaseResult2<List<ChildrenCategory>> listBaseResult2) throws Exception {
                            if (listBaseResult2.isSuccess()) {
                                v.setData(listBaseResult2.getData());
                            }
                        }
                    }, new Consumer<Throwable>() {
                        @Override
                        public void accept(Throwable throwable) throws Exception {
                            throwable.printStackTrace();
                            v.setError();
                        }
                    });
        }
    }

}
